﻿#if UNITY_EDITOR

using System;
using UnityEditor;
using UnityEngine;

namespace AI.Graph.Editor {


    public static class AIGraphPreferences {

        public enum Skin {

            Unity = 0,
            Personal = 1,
            Professional = 2

        }

        private static bool s_prefsLoaded;
        private static int s_skin = 0;

        public static Action<Skin> onSkinChanged;

        public static Skin skin {
            get {
                if (!s_prefsLoaded) {
                    s_skin = EditorPrefs.GetInt ("AI.Graph.Editor.Skin", 0);
                    s_prefsLoaded = true;
                }

                return (Skin) s_skin;
            }
            set {
                s_skin = (int) value;
                onSkinChanged?.Invoke ((Skin) s_skin);
                EditorPrefs.SetInt ("AI.Graph.Editor.Skin", s_skin);
            }
        }


        [PreferenceItem ("AI Graph")]
        static void OnPreferencesGUI () {
            EditorGUILayout.Space ();

            EditorGUILayout.LabelField ("Editor Skin", EditorStyles.boldLabel);

            int newSkin = EditorGUILayout.Popup ("Skin", (int) skin, new[] {"Unity", "Personal", "Pro"});

            if (newSkin != (int) skin) {
                skin = (Skin) newSkin;
            }

            EditorGUILayout.Space ();

            EditorGUILayout.LabelField ("Key bindings", EditorStyles.boldLabel);

            DrawKeyBinding ("Zoom", "Mouse Scroll Wheel (Scroll)");
            DrawKeyBinding ("Pan", "Mouse Scroll Wheel Click (Hold)");
            DrawKeyBinding ("Pan", "Alt + Left Mouse Button (Hold)");
            DrawKeyBinding ("Create Node", "Space");
            DrawKeyBinding ("Graph Context", "Right Mouse Button");
            DrawKeyBinding ("Node Context", "Right Mouse Button");
            DrawKeyBinding ("Port Context", "Right Mouse Button");
            DrawKeyBinding ("Transition Context", "Right Mouse Button");
            DrawKeyBinding ("New Transition", "Left Mouse Button");
            DrawKeyBinding ("Focus Selected Nodes", "F");
        }


        static void DrawKeyBinding (string label, string key) {
            EditorGUILayout.BeginHorizontal ();

            EditorGUILayout.PrefixLabel (label);

            GUI.enabled = false;
            EditorGUILayout.TextField (key);
            GUI.enabled = true;

            EditorGUILayout.EndHorizontal ();
        }

    }


}
#endif